import config from "../../../../../config/config";
// prefix
const prefixCls = config.prefix + '-table-column-checkbox'

export default {
  name: config.prefix + '-table-column-checkbox',
  props: {
    checked: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    },
    indeterminate: {
      type: Boolean,
      default: false
    },
    selectOnIndeterminate: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      currentChecked: this.checked
    }
  },
  watch: {
    checked (checked) {
      this.currentChecked = checked
    }
  },
  computed: {
    classes () {
      return [`${prefixCls}`,
              {
                [`${prefixCls}-checked`]: this.currentChecked,
                [`${prefixCls}-disabled`]: this.disabled,
                [`${prefixCls}-indeterminate`]: this.indeterminate
              }
      ]
    }
  },
  methods: {
    change (event) {
      this.currentChecked = event.target.checked
      this.$emit('change')
    },
    click () {
      if (this.disabled) {
        return false
      }
      if (this.indeterminate) {
        this.currentChecked = this.selectOnIndeterminate
      } else {
        this.currentChecked = !this.currentChecked
      }
      this.$emit('change')
    }
  }
}
